package jdbc419.dao;

import jdbc419.entity.dept;
import jdbc419.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author:SA
 * @DATA:DATA
 * 用户数据的持久化操作
 */


public class DeptDao {

    public dept selectdept(String dept_name,String address){

        //根据用户名 密码 完成用户的查询
        Connection connection = JDBCUtil.getConnection();
        PreparedStatement pstmt = null;
        dept dept01 = null;
        String sql = "select * from dept where dept_name=? and address=?";
        try {
            pstmt = connection.prepareStatement(sql);
            pstmt.setString(1,dept_name);
            pstmt.setString(2,address);
            ResultSet resultSet = pstmt.executeQuery();

            while(resultSet.next()){
                int dept_no = resultSet.getInt("dept_no");
                String deptname = resultSet.getString("dept_name");
                String ad = resultSet.getString("address");
                dept01 = new dept(dept_no,dept_name,ad);
            }
            return dept01;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.closeAll(null,pstmt,connection);
        }
        return dept01;

    };
}
